using AutoMapper;
using Pay.DTO;
using Pay.Data;
using Pay.IService;
using Pay.Core;
using System.Collections.Generic;

namespace Pay.Service.AutoMapper {
    public class CategoryMapper : IStartupDto {
        private IMapperConfigurationExpression _cfg;
        public CategoryMapper(IMapperConfigurationExpression cfg) {
            _cfg = cfg;
        }
        public void Execute() {
            Create();
        }
        protected virtual void Create() {
            _cfg.CreateMap<category_model, Category>()
                .ForMember(dest => dest.Id, src => src.MapFrom(c => c.id))
                .ForMember(dest => dest.ImagePath, src => src.MapFrom(c => c.image_urls.ToJson()))
                .ForMember(dest => dest.Name, src => src.MapFrom(c => c.name))
                .ForMember(dest => dest.ParentId, src => src.MapFrom(c => c.parent_id));
            _cfg.CreateMap<Category, category_dto>()
                .ForMember(dest => dest.id, src => src.MapFrom(c => c.Id))
                .ForMember(dest => dest.image_urls, src => src.MapFrom(c => c.ImagePath.ToObject<List<string>>()))
                .ForMember(dest => dest.name, src => src.MapFrom(c => c.Name))
                .ForMember(dest => dest.parent_id, src => src.MapFrom(c => c.ParentId))
                .ForMember(dest => dest.update_time, src => src.MapFrom(c => c.UpdateTime))
                .ForMember(dest => dest.is_disabled, src => src.MapFrom(c => c.IsDisabled))
                .ForMember(dest => dest.is_deleted, src => src.MapFrom(c => c.IsDeleted));
            _cfg.CreateMap<Category, category_ex>()
                .ForMember(dest => dest.id, src => src.MapFrom(c => c.Id))
                .ForMember(dest => dest.image_urls, src => src.MapFrom(c => c.ImagePath.ToObject<List<string>>()))
                .ForMember(dest => dest.name, src => src.MapFrom(c => c.Name))
                  .ForMember(dest => dest.merchant_id, src => src.MapFrom(c => c.MerchantId))
                .ForMember(dest => dest.in_rate, src => src.MapFrom(c => c.InRate))
                .ForMember(dest => dest.out_rate, src => src.MapFrom(c => c.OutRate))
                .ForMember(dest => dest.parent_id, src => src.MapFrom(c => c.ParentId));

            _cfg.CreateMap<Category, token_category_dto>()
                .ForMember(dest => dest.id, src => src.MapFrom(c => c.Id))
                .ForMember(dest => dest.name, src => src.MapFrom(c => c.Name))
                .ForMember(dest => dest.parent_id, src => src.MapFrom(c => c.ParentId))
                .ForMember(dest => dest.depth, src => src.MapFrom(c => c.Depth))
                .ForMember(dest => dest.path, src => src.MapFrom(c => c.Path))
                .ForMember(dest => dest.merchant_id, src => src.MapFrom(c => c.MerchantId))
                .ForMember(dest => dest.sort, src => src.MapFrom(c => c.Sort))
                  .ForMember(dest => dest.type, src => src.MapFrom(c => c.Type))
                .ForMember(dest => dest.update_time, src => src.MapFrom(c => c.UpdateTime))
                .ForMember(dest => dest.is_disabled, src => src.MapFrom(c => c.IsDisabled))
                .ForMember(dest => dest.is_deleted, src => src.MapFrom(c => c.IsDeleted))
                .ForMember(dest => dest.image_urls, src => src.MapFrom(c => c.ImagePath.ToObject<List<string>>()));

            _cfg.CreateMap<token_category_dto, Category>()
                .ForMember(dest => dest.Id, src => src.MapFrom(c => c.id))
                .ForMember(dest => dest.Name, src => src.MapFrom(c => c.name))
                .ForMember(dest => dest.ParentId, src => src.MapFrom(c => c.parent_id))
                .ForMember(dest => dest.Depth, src => src.MapFrom(c => c.depth))
                .ForMember(dest => dest.Path, src => src.MapFrom(c => c.path))
                .ForMember(dest => dest.MerchantId, src => src.MapFrom(c => c.merchant_id))
                .ForMember(dest => dest.Sort, src => src.MapFrom(c => c.sort))
                 .ForMember(dest => dest.Type, src => src.MapFrom(c => c.type))
                .ForMember(dest => dest.UpdateTime, src => src.MapFrom(c => c.update_time))
                .ForMember(dest => dest.IsDisabled, src => src.MapFrom(c => c.is_disabled))
                .ForMember(dest => dest.IsDeleted, src => src.MapFrom(c => c.is_deleted))
                .ForMember(dest => dest.ImagePath, src => src.MapFrom(c => c.image_urls.ToJson()));

        }
    }
}
